package class_01;

import java.util.ArrayList;
import java.util.Arrays;

/**
 * @author:连志鹏
 * @className:demo_01
 * @descrption:
 * @date: 2021/9/24 21:14
 * @version: 0.1
 * @since: 1.8
 */
public class demo_01 {


    public static void main(String[] args) {
        int num[] = {6,1, 2, 7, 9, 3, 4, 5, 10, 8};
        buSort_Asc(num);
        System.out.println(Arrays.toString(num));
        buSort_Des(num);
        System.out.println(Arrays.toString(num));
    }

    public int[] addList_01(int[] num,int value)
    {
        return addList(num,value);
    }

    //分解整数每位数字，以arraylist存储
    public ArrayList splitNum_01(int num){
        return splitNum(num);
    }
    //生成指定范围内的随机数(min<=random<max
    public int random_01(int min, int max)
    {
        return ran_01(min,max);
    }




    private static int ran_01(int min, int max){
        int random;
        double dou = Math.random();
        random = (int)(dou*(min-max)+max);
        return random;

    }


    private static int[] buSort_Des(int num[])
    {
        int ret = 0;
        for (int i = 1; i < num.length; i++) {
            for (int j = 0; j < num.length-i; j++) {
            if(num[j]>num[j+1])
                {
                    ret = num[j];
                    num[j] = num[j+1];
                    num[j+1] = ret;
                }
            }
        }
        return num;

    }

    private static int[] buSort_Asc(int num[])
    {
        int ret = 0;
        for (int i = 1; i < num.length; i++) {
            for (int j = 0; j < num.length-i; j++) {
                if(num[j]<num[j+1])
                {
                    ret = num[j];
                    num[j] = num[j+1];
                    num[j+1] = ret;
                }
            }
        }
        return num;
        
    }

    private static int[] addList(int[] num,int value)
    {
        int[] newAddList = new int[num.length+1];
        System.arraycopy(num,0,newAddList,0,num.length);
        newAddList[num.length] = value;
        return newAddList;

    }

    private static ArrayList splitNum(int num) {
        char[] ch = String.valueOf(num).toCharArray();
        ArrayList list = new ArrayList();
        int ret = 0;
        for (int i = 0; i < ch.length; i++) {
            ret = Integer.valueOf(ch[i])-48;
            list.add(ret);
        }
        return list;
    }




}
